from django.db import models

# Create your models here.
class Users(models.Model):
    # 用户用  密码 手机号 邮箱  性别 年龄 头像 注册时间 状态
    username = models.CharField(max_length=50)
    password = models.CharField(max_length=77)
    phone = models.CharField(max_length=11)
    email = models.CharField(max_length=100, null=True)
    sex = models.CharField(max_length=1,choices=((1,'男'),(0,'女')),null=True)
    age = models.IntegerField(null=True)
    pic_url = models.CharField(max_length=100,null=True)
    # 0 正常  1禁用
    status = models.IntegerField(default=0)
    addtime = models.DateTimeField(auto_now_add=True)

    class Meta:
        permissions = (
            ("show_user", "查看会员管理"),
            ("insert_user", "添加会员"),
            ("update_user", "修改会员"),
            ("del_user", "删除会员"),
        )



# 商品分类
class Cates(models.Model):
    name = models.CharField(max_length=50)
    pid = models.IntegerField()
    path = models.CharField(max_length=20)
    isDelete = models.BooleanField(default=False)
    # id  name  pid   path
      # 1    服装  0     0,
      # 2    男装  1     0,1,
      # 3    西服  2     0,1,2,
      # 4    女装  1     0,1,
      # 5    裙子  4     0,1,4,
      # 6    超短裙 5    0,1,4,5,
    class Meta:
        permissions = (
            ("show_cate", "查看商品分类管理"),
            ("insert_cate", "添加商品分类"),
            ("update_cate", "修改商品分类"),
            ("del_cate", "删除商品分类"),
        )

# 商品
class Goods(models.Model):
    # id  title cateid price store info pic_url status addtime clicknum ordernum
    title = models.CharField(max_length=255)
    cateid = models.ForeignKey(to='Cates')
    price = models.FloatField()
    store = models.IntegerField()
    info = models.TextField()
    pic_url = models.CharField(max_length=100)
    # 0 新发布 1 热卖 2 下架
    status = models.IntegerField(default=0)
    clicknum = models.IntegerField(default=0)
    ordernum = models.IntegerField(default=0)
    addtime = models.DateTimeField(auto_now_add=True)


    class Meta:
        permissions = (
            ("show_goods", "查看商品管理"),
            ("insert_goods", "添加商品"),
            ("update_goods", "修改商品"),
            ("del_goods", "删除商品"),
        )


# 购物车
class Cart(models.Model):
    # id goodsid 数量num
    uid = models.ForeignKey(to="Users")
    goodsid = models.ForeignKey(to="Goods")
    num = models.IntegerField()



# 城市地址
class Citys(models.Model):
    name = models.CharField(max_length=30)
    level = models.IntegerField()
    upid = models.IntegerField()


    class Meta:
        permissions = (
            ("show_city", "查看地址管理"),
            ("insert_city", "添加地址"),
            ("update_city", "修改地址"),
            ("del_city", "删除地址"),
        )

# 收货地址
class Address(models.Model):
  # uid          user shen shi xian qu info moren phone youbian 
  # 当前登录用户    用户  省  市  县   区  详情  默认   手机   邮编
    username = models.CharField(max_length=20)
    shen = models.CharField(max_length=30)
    shi = models.CharField(max_length=30)
    xian = models.CharField(max_length=30)
    zhen = models.CharField(max_length=30,null=True)
    info = models.CharField(max_length=100)
    status = models.BooleanField(default=False)
    phone = models.CharField(max_length=11)
    code = models.CharField(max_length=30)
    uid = models.ForeignKey(to="Users")


# 订单
class Order(models.Model):
    # 当前用户 地址  总价   购买时间  商品id 商品数量  支付方式  状态  订单号
    address = models.CharField(max_length=300)
    priceSum = models.FloatField()
    addtime = models.DateTimeField(auto_now_add=True)
    mode = models.CharField(max_length=30)
    dingId = models.CharField(max_length=30)
    status = models.IntegerField(default=0)
    userid = models.ForeignKey(to="Users")


    class Meta:
        permissions = (
            ("show_order", "查看订单管理"),
            ("insert_order", "添加订单"),
            ("update_order", "修改订单"),
            ("del_order", "删除订单"),
        )

# 订单详情
class OrderInfo(models.Model):
  # 商品id  订单id  数量 
  title = models.CharField(max_length=100)
  price = models.FloatField()
  pic_url = models.CharField(max_length=100)

  gid = models.IntegerField()
  oid = models.ForeignKey(to="Order")
  num = models.IntegerField()
